<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{:session('cp.cpsysname')}--服务商管理平台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="{:config('webconfig.description');}">
    <meta name="keywords" content="{:config('webconfig.keywords');}">
    <meta name="author" content="runoob">
    <link rel="stylesheet" href="__STATIC_URL__/static/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/index.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/css/addmchat.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css"/>
    <script src="__STATIC_URL__/static/jquery/2.2.1/jquery.min.js"></script>
    <script src="__STATIC_URL__/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>
    <script src="__STATIC_URL__/static/js/commen.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC_URL__/static/layer/layer.js"></script>

    <style>
        thead tr th {
            text-align: center;
        }

        tbody tr td {
            text-align: center;
        }

        .content .panel-search {
            border: 1px solid #d0f2f7;
        }

        .panel-default > .panel-heading {
            background: #EEF8FC;
            color: #26929C;
        }
    </style>
</head>
<body>
{include file='public/header'/}
<!------------------导航-------------------------->
<section id="content">
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading">
            <ul class="breadcrumb mgl15 mgr15">
                <li>当前位置是:</li>
                <li>
                    <a href="javascript:history.back();">商户管理</a>
                </li>
                <li>
                    <a href="javascript:history.back();">商户列表</a>
                </li>
                <li class="active" style="color: #02b87f;">门店列表</li>
            </ul>
        </div>
        <div class="panel panel-search panel-default mgl15 mgr15">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <span class="glyphicon glyphicon-search pull-left" style="margin-right: 10px;"></span>筛选分类
                </h3>
            </div>
            <div class="panel-body">
                <form action="" method="get" class="form-horizontal table-search form-search" role="form" id="machform">
                    <div class="col-sm-6 col-md-6 col-lg-4 ">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">门店名称：</label>
                            <div class="col-sm-9">
                                <select name="merchant" id="" class="form-control">
                                    <option value="">所有门店</option>
                                    {volist name="machlist" id="search"}
                                    <option value="{$search.merchant}" {if condition="$p_data['merchant'] eq $search.merchant"}selected{/if}>{$search.merchant}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="panel-footer">
                <a href="javascript:;" class="btn btn-primary" onclick="searchform()">查找</a>
                <a href="javascript:;" class="btn btn-default" onclick="clearform()">清空</a>
            </div>
        </div>
        <div class="panel panel-default mgl15 mgr15">
            <div class="panel-heading addCharts" style="background:#ededed;">门店列表</div>
            <div class="panel-body">
                <table class="table table-bordered" data-toolbar="#toolbar">
                    <thead>
                    <tr>
                        <th data-type="0">门店编号</th>
                        <th data-type="1">门店名称</th>
                        <th data-type="2">商户号</th>
                        <th>商户</th>
                        <th>隶属服务商</th>
                        <th>业务员</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="mach" id="vo"}
                    <tr>
                        <td class="mid">{$vo.id}</td>
                        <td class="mid">{$vo.merchant}
                            <span data-urloneshow="{:url('momach/getmercode',array('mid'=>$vo['id']))}"  data-urltwoshow="{:url('momach/getqrcode',array('mid'=>$vo['id']))}"  data-urlone="/mercode/{$vo.id}.png" data-urltwo="/qrcode/{$vo.id}.png"  class="btn-lg glyphicon glyphicon-qrcode" data-toggle="modal"  data-target="#myModal" style="color:deepskyblue;margin-left: 5px;cursor: pointer;font-size: 12px;"> </span>
                        </td>
                        <td class="mid">
                            {if condition="$vo.shtd eq '0' "}
                            {$vo.sub_mch_id}
                            {elseif condition="$vo.shtd eq '1' "/}
                            {$vo.cmmb_mer_id}
                            {/if}
                        </td>
                        <td class="mid">{:getmomach($vo['top_mid'],'name')}</td>
                        <td class="mid">{:getagent($vo['agent'],"name")}</td>
                        <td class="mid">{:getsales($vo['salesman'])}</td>
                        <td class="mid">

                            {if condition="checkPath('momach/machinfo')"}
                            <a class="btn-link" href="{:url('momach/machinfo')}?id={$vo.id}"> 查看</a>
                            {/if}
                            <a class="btn-link" href="{:url('momach/machxg')}?id={$vo.id}"> 修改</a>
                            {if condition="checkPath('momach/delmach')"}
                            <a class="btn-link deletemach" data-id="{$vo['id']}" data-name="{$vo.merchant}">删除</a>
                            {/if}
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
            {$mach->render()}
        </div>
        {include file='public/footer'/}
    </div>
</section>
<!-- 设备列表展示Modal 开始-->
<div class="modal fade" id="equipment" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width: 800px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="equipmentLabel">设备列表</h4>
            </div>
            <div class="modal-body">
                {if condition="checkPath('mach/add_device_micro')"}
                <a href="javascript:;" style="margin-bottom: 6px;" class="gobang btn btn-success pull-right"  data-toggle="modal" data-target="#bangding">生成码</a>
                {/if}
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>设备名称</th>
                        <th>状态</th>
                        <th>绑定码</th>
                    </tr>
                    </thead>
                    <tbody id="tk-tbody">

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<!-- 设备列表展示Modal 结束-->
<!-- 生成绑定吗 Modal 开始-->
<div class="modal fade" id="bangding" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="bangdingLabel">生成绑定码</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="bangdingform">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">设备名称：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="device_name" placeholder="请输入设备名称"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">退款密码：</label>
                        <div class="col-sm-9">
                            <input type="hidden" id="scbdm" name="mid"/>
                            <input type="hidden" id="is_tk" name="is_tk" value="1"/>
                            <input type="text" class="form-control" name="tk_pass" placeholder="请输入密码"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="bingsure">生成</button>
            </div>
        </div>
    </div>
</div>
<!-- 生成绑定吗 Modal 结束-->
<!-- 修改绑定退款密码Modal 开始-->
<div class="modal fade" id="xgbangding" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="xgbangdingLabel">绑定收银设备</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="xgbangdingform">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">退款密码：</label>
                        <div class="col-sm-9">
                            <input type="hidden" id="tkid" name="id"/>
                            <input type="text" name="tk_pass" class="form-control" placeholder="请输入密码"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="xgbingsure">完成</button>
            </div>
        </div>
    </div>
</div>
<!-- 修改绑定退款密码Modal 结束-->
<!-- 二维码下载模态框（Modal） 开始-->
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    二维码
                </h4>
            </div>
            <div class="modal-body">
                <ul id="myTab" class="nav nav-tabs">
                    {if condition="checkPath('momach/getqrcode')"}
                    <li class="active tabios"><a href="#ios" data-toggle="tab">单独二维码</a></li>
                    {/if}
                    {if condition="checkPath('momach/getmercode')"}
                    <li class="tabhome">
                        <a href="#home" data-toggle="tab">
                            收款二维码
                        </a>
                    </li>
                    {/if}

                </ul>
                <div id="myTabContent" class="tab-content">
                    {if condition="checkPath('momach/getmercode')"}
                    <div class="tab-pane  in text-center" id="home">
                        <h3>该功能暂时下线！</h3>
                    </div>
                    {/if}
                    {if condition="checkPath('momach/getqrcode')"}
                    <div class="tab-pane active text-center" id="ios">
                        <img src="" alt=""/>
                        <a href="" id="codetwo" class="btn btn-primary"> 点击下载 </a>
                    </div>
                    {/if}
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- 二维码下载模态框（Modal） 结束-->
<script src="__STATIC_URL__/static/js/clipboard.min.js"></script>
<script>
    $(document).ready(function(){
        var clipboard = new Clipboard('.copy_btn');


        clipboard.on('success', function(e) {
            alert(1);
        });

        clipboard.on('error', function(e) {
            alert(2);
        });
    })

</script>
</body>

<script src="__STATIC_URL__/static/js/template.js"></script>


<!--设备列表 模型 开始-->
<script id="modallist" type="text/html">
    {{each list value i}}
    <tr>
        <td>{{list[i].device_name}}</td>
        <td>
            {{ if (list[i].status == '1') }}
            <a href="javascript:;" class="xgbang btn-link" data-id="{{list[i].id}}" data-toggle="modal" data-target="#xgbangding">修改</a>
            <a href="javascript:;" class="delbang btn-link" data-id="{{list[i].id}}">解绑</a>
            {{/if}}
            {{ if (list[i].status == '0') }}
            未绑定
            {{/if}}
        </td>
        <td>
            <div class="">
                <input type="text" class="form-control"  readonly  value="{{list[i].code}}">
                <!--<span class="input-group-addon copy_btn" data-clipboard-text="{{list[i].code}}">复制</span>-->
            </div>
        </td>
    </tr>
    {{/each}}
</script>
<!--设备列表 模型 结束-->
<script type="text/javascript">
    function getDatas(val){
        var url= "{:url('pay/requestname')}";
        $.ajax({
            url:url,
            type:"post",
            data:{
                merchant:val
            },
            success:function(data){
                if(data!=""){
                    var list = "";
                    for(var i=0;i<data.length;i++){
                        list+="<li>"+data[i].merchant+"</li>";
                    }
                    $(".searchlist ul").html(list);
                    $(".searchlist").removeClass("hide");
                }else{
                    $(".searchlist ul").html('');
                    $(".searchlist").addClass("hide");
                }
            }
        })
    }
    $(function () {
//        设备列表模态框 显示 获取数据 开始
        $("#equipment").on('show.bs.modal', function () {
            //                    判断是否有权限修改密码
            var qx = "{:checkPath('mach/device_micro_view')}";
            if(qx==0){
                layer.alert("您没有权限进行访问",{icon:7});
                return false;
            }
            var id = $(event.target).data("id");
            $("#scbdm").val(id);
            var datas = {};
            $.ajax({
                url:"{:url('mach/device_micro_view')}",
                type:"post",
                data:{
                    mid:id
                },
                success:function(data){
                    datas.list = data;
                    var html = template('modallist', datas);
                    $("#tk-tbody").html(html);
                }
            })
        });
        $("#equipment").on('hide.bs.modal', function () {
            $("#scbdm").val("");
        });
//        设备列表模态框 显示 获取数据 结束

//        生成绑定码 开始
        $("#bangding").on('show.bs.modal', function () {
            var mid = $(event.target).data("id");
            var name = $(event.target).data("name");
            $("#tkmid").val(mid);
            $("#device-name").val(name);
        });
        $("#bingsure").click(function(){
            $.ajax({
                url:"{:url('mach/add_device_micro')}",
                type:"post",
                data:$("#bangdingform").serialize(),
                success:function(data){
                    if(data.code==0){
                        layer.msg(data.message,{icon:1});
                        setTimeout("window.location.reload()",1000)
                        return false;
                    }else{
                        layer.alert(data.message);
                        return false;
                    }
                }
            })
        });
//        生成绑定码 结束

//        修改绑定密码 开始
        $("#xgbangding").on('show.bs.modal', function () {
            //                    判断是否有权限修改密码
            var qx = "{:checkPath('mach/device_micro_md_pass')}";
            if(qx==0){
                layer.alert("您没有权限进行修改",{icon:7});
                return false;
            }
            var mid = $(event.target).data("id");
            $("#tkid").val(mid);
        });
        $("#xgbingsure").click(function(){
            $.ajax({
                url:"{:url('mach/device_micro_md_pass')}",
                type:"post",
                data:$("#xgbangdingform").serialize(),
                success:function(data){
                    if(data.code==0){
                        layer.msg("绑定成功",{icon:1});
                        setTimeout("window.location.reload()",1000)
                        return false;
                    }else{
                        layer.alert(data.message);
                        return false;
                    }
                }
            })
        });
//        修改绑定密码 结束

//        解绑绑定密码 开始
        $("#tk-tbody").on("click",".delbang",function(){
            //                    判断是否有权限修改密码
            var qx = "{:checkPath('mach/device_mirco_jb')}";
            if(qx==0){
                layer.alert("您没有权限进行解绑",{icon:7});
                return false;
            }
            var id = $(this).attr("data-id");
            layer.confirm('正在进行解绑操作！', {
                btn: ['确认','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"{:url('mach/device_mirco_jb')}",
                    type:"post",
                    data:{
                        id:id
                    },
                    success:function(data){
                        if(data.code==0){
                            layer.msg("解绑成功",{icon:1});
                            setTimeout("window.location.reload()",1000);
                            return false;
                        }else{
                            layer.alert("解绑失败");
                            return false;
                        }
                    }
                })
            }, function(){

            });

        });
//        解绑绑定密码 结束
        $("tr th").click(function (event) {
            var sort = $(event.target).find("span");
            var type = $(event.target).data("type");
            if (sort.hasClass("glyphicon-sort")) {
                sort.removeClass("glyphicon-sort").addClass("glyphicon-arrow-down");
            } else if (sort.hasClass("glyphicon-arrow-down")) {
                sort.removeClass("glyphicon-arrow-down").addClass("glyphicon-arrow-up");
            } else if (sort.hasClass("glyphicon-arrow-up")) {
                sort.removeClass("glyphicon-arrow-up").addClass("glyphicon-sort");
            }
        });
        $("tr th span").click(function () {
            var sort = $(event.target);
            if (sort.hasClass("glyphicon-sort")) {
                sort.removeClass("glyphicon-sort").addClass("glyphicon-arrow-down");
            } else if (sort.hasClass("glyphicon-arrow-down")) {
                sort.removeClass("glyphicon-arrow-down").addClass("glyphicon-arrow-up");
            } else if (sort.hasClass("glyphicon-arrow-up")) {
                sort.removeClass("glyphicon-arrow-up").addClass("glyphicon-sort");
            }
        })
    })
</script>
<script type="text/javascript">
    $(function () {
//        getsales();
        $('#myModal').on('show.bs.modal', function () {
            var code = "{:checkPath('mach/qrcode')}";
//            if(code == 0||code == ""){
//                layer.alert("没有权限访问");
//                return false;
//            }
            var getmercode = "{:checkPath('momach/getqrcode')}";
            var getqrcode = "{:checkPath('momach/getqrcode')}";
            if(getmercode=="" && getqrcode==""){
                layer.alert("没有权限访问");
                return false;
            }
            if(getmercode == "0" ){
                $(".tabios").addClass("active");
                $("#ios").addClass("active").addClass("in");
            }
            var url1 = $(event.target).data("urlone");
            var url2 = $(event.target).data("urltwo");

            var url1show = $(event.target).data("urloneshow");
            var url2show = $(event.target).data("urltwoshow");
            $("#home img").attr("src", url1show);
            $("#ios img").attr("src", url2show);
            $("#codeone").attr("href", url1).attr("download",url1);
            $("#codetwo").attr("href", url2).attr("download",url2);
        })
        $('#myModal').on('hide.bs.modal', function () {
            $("#home img").attr("src", '');
            $("#ios img").attr("src", '');
        });
        $(".deletemach").click(function (event) {
            var id = $(event.target).data("id");
            var name = $(event.target).data("name");
            layer.confirm('正在删除商户' + name + ',删除后将不可恢复\n是否继续删除', {
                btn: ['确认','取消'] //按钮
            }, function(){
                $.ajax({
                    url: "{:url('momach/delmach')}",
                    data: {
                        id: id
                    },
                    type: "post",
                    success: function (data) {
                        // console.log(data)
                        if(data.code==0){
                            layer.msg("删除成功", {icon: 1,time:1000});
                            setTimeout("window.location.reload()",1000);
                            return false;
                        }else{
                            layer.alert(data.message);
                            return false
                        }
                    }
                })
            }, function(){

            });
        })
    });
    function opt() {
        $('#classes2').html('<option value="">请选择类别</option>');
        var id = $('#classes1').val();
        $.ajax({
            type: 'GET',
            url: "{:url('Public/getlevel')}",
            dataType: "json",
            data: {
                leveltop: id,
            },
            success: function (data) {
                var da = eval("(" + data + ")");

                $.each(da, function (n, value) {
                    var HTML = "<option value='" + value.id + "'>" + value.level + "</option>";
                    $('#classes2').append(HTML);

                })
            }
        })
    }
</script>

</html>
